# -*- coding: utf-8 -*-
import pprint
import utils
import locale
import datetime
from db import Stock
from manager import RawDataManager, StockInfoManager, StatusManager

if __name__ == '__main__':
    # Test 1: get_raw_data test
    #raw_data = utils.get_raw_data('sina', 2012, 4, 13, 'sh', '600572')
    #if raw_data != utils.ERROR:
    #    pprint.pprint(raw_data)

    # Test 2: database test.
    conn = Stock('192.168.1.2', 'root', '123456')

    # Test 3: fill sz company info and character set encoding 
    #sz_com_info = utils.get_sz_company()
    #conn.fill_info_table('sz', sz_com_info)
    #pprint.pprint(sz_com_info)
    #conn.fetch_stock_info('sz000001')

    # Test 4: fill sh company info
    #sh_com_info = utils.get_sh_company()
    #conn.fill_info_table('sh', sh_com_info)
    #conn.fetch_stock_info('sh600000')

    # Test 5: update_info_table
    #print(utils.get_root_dir())
    #conn.update_info_table('sz', old_info_list, info_list)

    # Test 6: create per stock table
    #conn.create_per_stock_table()

    # Test 7: download per stock data from sina
    #rows = conn.query_stock_code()
    #for r in rows:
    #    raw_data = utils.get_raw_data('sina', 2012, 4, 13, r)

    # Test 8: download per stock data via collector.
    #sm = StatusManager(conn)
    #StockInfoManager(conn)
    #RawDataManager(conn)
    #sm.maintain()
    
    # Datetime ++
    begin = datetime.date(2012, 1, 1) # 2012-1-1
    today = datetime.date.today()
    delta = today - begin       # total days from 2000-1-1 to today
    date = begin
    for i in range(delta.days):
        print(date)
        date += datetime.timedelta(days=1)
